package com.example.yunJie.digitalSentry;

import com.alibaba.fastjson.JSONObject;
import com.example.yunJie.digitalSentry.component.ApplicationContextUtil;
import com.example.yunJie.digitalSentry.entity.*;
import com.example.yunJie.digitalSentry.service.*;
import com.example.yunJie.digitalSentry.util.UrlConnection;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.text.SimpleDateFormat;
import java.util.*;

@MapperScan("com.example.yunJie.digitalSentry.mapper")
@SpringBootApplication
@EnableScheduling
public class DigitalsentryApplication {

    public static void main(String[] args) {
        SpringApplication.run(DigitalsentryApplication.class, args);

    }
//
//    @Scheduled(cron = "0 */2 * * * ?")
//    public static void insert() throws Exception {
//
//        MarketService marketService = ApplicationContextUtil.getBean(MarketService.class);
//        PersonalService personalService = ApplicationContextUtil.getBean(PersonalService.class);
//        RecognitionService recognitionService = ApplicationContextUtil.getBean(RecognitionService.class);
//        ClockService clockService = ApplicationContextUtil.getBean(ClockService.class);
//        SchedulingService schedulingService = ApplicationContextUtil.getBean(SchedulingService.class);
//        PostService postService = ApplicationContextUtil.getBean(PostService.class);
//        ShiftService shiftService = ApplicationContextUtil.getBean(ShiftService.class);
//        ShiftDateService shiftDateService = ApplicationContextUtil.getBean(ShiftDateService.class);
//        DateService dateService = ApplicationContextUtil.getBean(DateService.class);
//
//        Calendar calendar = new GregorianCalendar();
//        Date time = calendar.getTime();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        SimpleDateFormat sdf2 = new SimpleDateFormat("EEEE");
//        String format = sdf.format(time);
//        String format1 = sdf2.format(time);
//        String format2 = sdf1.format(time);
////        System.out.println(calendar.getTime());
////        System.out.println(format);
////        System.out.println(format1);
//        List<RecognitionEntity> allByCapture_time = recognitionService.findAllByCapture_time(format);
//        for (RecognitionEntity re : allByCapture_time) {
//            ClockEntity clockEntity1 = new ClockEntity();
//            clockEntity1.setClockingTime(sdf1.parse(re.getCapture_time()));
//            clockEntity1.setPersonalName(re.getPerson_name());
//            if (clockService.findAllByPersonalNameAndClockingTime(clockEntity1) == null) {
//                PersonalEntity personalEntity = personalService.findByPersonalName(re.getPerson_name());
//                    try {
//                        SchedulingEntity schedulingEntity = schedulingService.findByPersonalId(String.valueOf(personalEntity.getId()));
//                    }catch (Exception e){
//                        e.printStackTrace();
//                        continue;
//                    }
//                    SchedulingEntity schedulingEntity = schedulingService.findByPersonalId(String.valueOf(personalEntity.getId()));
//                    if (schedulingEntity != null) {
//                        ClockEntity clockEntity = new ClockEntity();
//                        clockEntity.setClockingTime(sdf1.parse(re.getCapture_time()));
//                        clockEntity.setPersonalName(re.getPerson_name());
//                        clockEntity.setMarketId(personalEntity.getMarketId());
//                        clockEntity.setPostId(personalEntity.getPostId());
//                        clockEntity.setShiftId(schedulingEntity.getShiftId());
//                        clockEntity.setMarketName(marketService.findId(personalEntity.getMarketId()).getMarketName());
//                        clockEntity.setPostName(postService.findId(personalEntity.getPostId()).getPostName());
//                        clockEntity.setShiftName(shiftService.findId(schedulingEntity.getShiftId()).getShiftName());
//                        List<ShiftDateEntity> byShiftId = shiftDateService.findByShiftId(schedulingEntity.getShiftId());
//                        for (ShiftDateEntity shiftDateEntity : byShiftId) {
//                            DateEntity dateEntity = dateService.findId(shiftDateEntity.getDateId());
//                            if (dateEntity.getDate().equals(format2) || dateEntity.getDate().equals(format1)) {
//                                clockEntity.setClockStatus("正常");
//                                break;
//                            } else {
//                                clockEntity.setClockStatus("不正常");
//                            }
//                        }
////                    System.out.println(clockEntity);
////                    System.out.println(re);
////                    System.out.println(personalEntity);
//                        clockService.insert(clockEntity);
//                }
//            }
//        }
//    }
//
//    @Scheduled(cron = "0 */10 * * * ?")
//    public void faceDown() {
//        FaceDownService faceDownService = ApplicationContextUtil.getBean(FaceDownService.class);
//        EquipmentService equipmentService = ApplicationContextUtil.getBean(EquipmentService.class);
//        EquipmentEntity equipmentEntity = new EquipmentEntity();
//        List<EquipmentEntity> all = equipmentService.findAll(equipmentEntity);
//        List<String> list = new ArrayList<>();
//        for (EquipmentEntity equipmentEntity1 : all){
//            list.add(equipmentEntity1.getEquipmentNumber());
//        }
//        String requestUrl = "http://101.89.133.43:5180/deliverySyncPersonToDevice";
//        Map<String, Object> map = new HashMap<String, Object>();
////        String[] stringList = new String[]{"JWJA220505130","JWJA220511023","JWJA220511026","JWJA220511061","JWJA220511079","JWJA220507028","JWJA220507033","JWJA220511127","JWJA220507029","JWJA220511117","JWJA220507030","JWJA220511099","JWJA220511098","JWJA220511078","JWJA220511101","JWJA220511100","JWJA220511081","JWJA220505115","JWJA220505003","JWJA220429020","JWJA220505107","JWJA220505109","JWJA220505120"};
////        String[] stringList = new String[]{"JWJA220511127"};
////        for (int i = 0; i < stringList.length; i++) {
//            for (String s : list){
//                List<FaceDownEntity> byDevSno = faceDownService.findByDevSno(s);
//                for (FaceDownEntity faceDownEntity : byDevSno) {
////                System.out.println(faceDownEntity);
//                    faceDownEntity.setDevSno(s);
//                    map.put("devSno", faceDownEntity.getDevSno());
//                    map.put("pidList", faceDownEntity.getPidList() + ";");
//                    map.put("idCardList", faceDownEntity.getIdCardList() + ";");
//                    map.put("personNameList", faceDownEntity.getPersonNameList() + ";");
//                    String templateImgUrlList = faceDownEntity.getTemplateImgUrlList();
//                    String replace = templateImgUrlList.replace("C:", "http://101.89.133.43:89");
//                    String replace1 = replace.replace("\\", "/");
//                    map.put("templateImgUrlList", replace1 + ";");
//                    JSONObject json = new JSONObject(map);
//                    String s1 = UrlConnection.sendPost(requestUrl, json.toJSONString(), null);
////                System.out.println(s);
//                }
////            }
//
//        }
//    }
//
//
//    @Scheduled(cron = "0 */10 * * * ?")
//    public void personalltofacedown() {
//        FaceDownService faceDownService = ApplicationContextUtil.getBean(FaceDownService.class);
//        PersonalService personalService = ApplicationContextUtil.getBean(PersonalService.class);
//        MarketService marketService = ApplicationContextUtil.getBean(MarketService.class);
//        EquipmentService equipmentService = ApplicationContextUtil.getBean(EquipmentService.class);
//        PersonalEntity personalEntity = new PersonalEntity();
//        List<PersonalEntity> all = personalService.findAll(personalEntity);
//        for (PersonalEntity personalEntity1 : all) {
//            FaceDownEntity faceDownEntity = new FaceDownEntity();
//            faceDownEntity.setPersonNameList(personalEntity1.getPersonalName());
//            faceDownEntity.setTemplateImgUrlList(personalEntity1.getPersonalPhoto());
//            faceDownEntity.setPidList(personalEntity1.getId());
//            MarketEntity id = marketService.findId(personalEntity1.getMarketId());
//            EquipmentEntity equipmentEntity = new EquipmentEntity();
//            equipmentEntity.setMarketName(id.getMarketName());
//            List<EquipmentEntity> all1 = equipmentService.findAll(equipmentEntity);
//            StringBuilder sb = new StringBuilder();
//            for (EquipmentEntity equipmentEntity1 : all1) {
//                sb.append(equipmentEntity1.getEquipmentNumber());
//                sb.append(";");
//            }
//            faceDownEntity.setDevSno(sb.toString());
//            faceDownEntity.setIdCardList(personalEntity1.getPersonalCardNumber());
//
//            if (faceDownService.findBypidList(personalEntity1.getId()) == null) {
////                System.out.println(faceDownEntity);
//                faceDownService.insert(faceDownEntity);
//            }
//
//        }
//
//    }


}
